//
//  ChooseTypeView.m
//  YiTangZuoWenKe
//
//  Created by work on 2017/4/13.
//  Copyright © 2017年 wyp. All rights reserved.
//身份选择的View

#import "ChooseTypeView.h"

@interface ChooseTypeView()
/**选择身份*/
@property (nonatomic ,strong) UILabel *titleLabel;
/**下划线*/
@property (nonatomic ,strong) UIView *lineView;
/**游客图*/
@property (nonatomic ,strong) UIButton *touristIconBtn;
/**我是游客*/
@property (nonatomic ,strong) UILabel *touristLab;
/**游客选择按钮*/
@property (nonatomic ,strong) UIButton *touristChoiceBtn;
/**本地人图*/
@property (nonatomic ,strong) UIButton *nativeIconBtn;
/**我是本地人*/
@property (nonatomic ,strong) UILabel *nativeLab;
/**本地人选择按钮*/
@property (nonatomic ,strong) UIButton *nativeChoiceBtn;
/**完成按钮*/
@property (nonatomic ,strong) UIButton *completeBtn;

@end
@implementation ChooseTypeView
#pragma mark- init初始化
- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self addSubView];
    }
    return self;
}
- (void)addSubView{
    [self addSubview:self.titleLabel];
    [self addSubview:self.touristIconBtn];
    [self addSubview:self.touristChoiceBtn];
    [self addSubview:self.touristLab];
    [self addSubview:self.nativeIconBtn];
    [self addSubview:self.nativeChoiceBtn];
    [self addSubview:self.nativeLab];
    [self addSubview:self.completeBtn];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(BY_Height(26));
        make.left.right.equalTo(self);
    }];
    [self.touristIconBtn mas_makeConstraints:^(MASConstraintMaker *make) {//游客图
        make.top.equalTo(self.titleLabel.mas_bottom).with.offset(BY_Height(72));
        make.width.height.equalTo(@(KSCREEWIDTH - BY_Width(208*2)));
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
    [self.touristLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.touristIconBtn.mas_bottom).offset(BY_Height(36));
        make.centerX.equalTo(self.touristIconBtn.mas_centerX).offset(BY_Width(48/2));
    }];
    [self.touristChoiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.touristLab.mas_left).offset(BY_Width(-10));
        make.centerY.equalTo(self.touristLab.mas_centerY);
        make.width.height.offset(BY_Width(48));
    }];
    [self.nativeIconBtn mas_makeConstraints:^(MASConstraintMaker *make) {//当地居民图
        make.top.equalTo(self.touristLab.mas_bottom).offset(BY_Height(60));
        make.width.height.equalTo(self.touristIconBtn);
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
    [self.nativeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nativeIconBtn.mas_bottom).offset(BY_Height(36));
        make.centerX.equalTo(self.nativeIconBtn.mas_centerX).offset(BY_Width(48/2));
    }];
    [self.nativeChoiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.nativeLab.mas_left).offset(BY_Width(-10));
        make.centerY.equalTo(self.nativeLab.mas_centerY);
        make.width.height.offset(BY_Width(48));
    }];
    [self.completeBtn mas_makeConstraints:^(MASConstraintMaker *make) {//完成按钮
        make.top.equalTo(self.nativeLab.mas_bottom).offset(BY_Height(108));
        make.height.offset(BY_Height(80));
        make.centerX.equalTo(self);
        make.width.offset(BY_ScreenWidth - BY_Width(60*2));
    }];
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = BYColor1;
        _titleLabel.font = BYPTFont36;
        _titleLabel.text = @"选择身份";
        [_titleLabel sizeToFit];
    }
    return _titleLabel;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = COLOR1;
        [_lineView sizeToFit];
    }
    return _lineView;
}
- (UIButton *)touristIconBtn{//游客图
    if (!_touristIconBtn) {
        _touristIconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_touristIconBtn setBackgroundImage:[UIImage imageNamed:@"mineIcon_choice_tourist_D"] forState:UIControlStateNormal];
        [_touristIconBtn setBackgroundImage:[UIImage imageNamed:@"mineIcon_choice_tourist_S"] forState:UIControlStateSelected];
        [_touristIconBtn addTarget:self action:@selector(imageClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _touristIconBtn;
}
-(UIButton *)touristChoiceBtn{//游客选择按钮
    if (!_touristChoiceBtn) {
        _touristChoiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _touristChoiceBtn.userInteractionEnabled = YES;
        [_touristChoiceBtn setBackgroundImage:[UIImage imageNamed:@"mineIcon_choice_S"] forState:UIControlStateSelected];
        [_touristChoiceBtn setBackgroundImage:[UIImage imageNamed:@"mineIcon_choice_D"] forState:UIControlStateNormal];
    }
    return _touristChoiceBtn;
}
- (UILabel *)touristLab{//我是游客
    if (!_touristLab) {
        _touristLab = [[UILabel alloc]init];
        _touristLab.textAlignment = NSTextAlignmentCenter;
        _touristLab.textColor = BYColor2;
        _touristLab.font = BYPTFont36;
        _touristLab.text = @"我是游客";
    }
    return _touristLab;
}
- (UILabel *)nativeLab{//我是当地居民
    if (!_nativeLab) {
        _nativeLab = [[UILabel alloc]init];
        _nativeLab.textAlignment = NSTextAlignmentCenter;
        _nativeLab.textColor = BYColor2;
        _nativeLab.font = BYPTFont36;
        _nativeLab.text = @"我是当地居民";
    }
    return _nativeLab;
}
- (UIButton *)nativeChoiceBtn{//当地居民选择按钮
    if (!_nativeChoiceBtn) {
        _nativeChoiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _nativeChoiceBtn.userInteractionEnabled = YES;
        [_nativeChoiceBtn setBackgroundImage:[UIImage imageNamed:@"mineIcon_choice_S"] forState:UIControlStateSelected];
        [_nativeChoiceBtn setBackgroundImage:[UIImage imageNamed:@"mineIcon_choice_D"] forState:UIControlStateNormal];
    }
    return _nativeChoiceBtn;
}
- (UIButton *)nativeIconBtn{//当地居民
    if (!_nativeIconBtn) {
        _nativeIconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_nativeIconBtn setBackgroundImage:[UIImage imageNamed:@"mineIcon_choice_native_D"] forState:UIControlStateNormal];
         [_nativeIconBtn setBackgroundImage:[UIImage imageNamed:@"mineIcon_choice_native_S"] forState:UIControlStateSelected];
        [_nativeIconBtn addTarget:self action:@selector(imageClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nativeIconBtn;
}
- (UIButton *)completeBtn{//完成按钮
    if (!_completeBtn) {
        _completeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_completeBtn addTarget:self action:@selector(completeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_completeBtn setTitle:@"完成" forState:UIControlStateNormal];
        _completeBtn.titleLabel.font = BYPTFont36;
        [_completeBtn setTitleColor:BYColor3 forState:UIControlStateNormal];
//        [_completeBtn setBackgroundColor:BYColor4];
        [_completeBtn setBackgroundColor:BYGrayColor];
        _completeBtn.layer.cornerRadius = BY_Width(10);
        _completeBtn.layer.masksToBounds = YES;
        _completeBtn.enabled = NO;
    }
    return _completeBtn;
}
- (void)imageClick:(id)sender{//选择方法
    UIButton *btn = (UIButton *)sender;
    if (btn == self.touristIconBtn) {//点击了游客
        _touristIconBtn.selected = YES;
        self.touristChoiceBtn.selected = YES;
        _nativeIconBtn.selected = NO;
        self.nativeChoiceBtn.selected = NO;
    }else{//点击了当地居民
        _touristIconBtn.selected = NO;
        self.touristChoiceBtn.selected = NO;
        _nativeIconBtn.selected = YES;
        self.nativeChoiceBtn.selected = YES;
    }
    [_completeBtn setBackgroundColor:BYColor4];
    _completeBtn.enabled = YES;
}
- (void)completeBtnClick:(UIButton *)btn{//点击了确认按钮
    NSString *typeStr = self.nativeChoiceBtn.selected ? @"tea" : @"stu";//判断是否是本地人
    if (self.clickCompleteBtn) {
        self.clickCompleteBtn(typeStr);
    }
}


@end
